package cn.yunbamboos.rest.service.apidoc.meta.schema;

import cn.yunbamboos.rest.service.apidoc.meta.Schema;
import com.alibaba.fastjson2.JSONObject;


public abstract class BaseSchema implements Schema {

    protected final String path;
    protected final String type;
    protected String title;
    protected String example;

    public BaseSchema(String path, String type) {
        this.path = path;
        this.type = type;
    }

    @Override
    public void addProperty(String name, Schema schema) {
    }

    @Override
    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public void addRequired(String required) {
    }

    @Override
    public void setItems(Schema items) {
    }

    public void setExample(String example) {
        this.example = example;
    }

    @Override
    public void toExample(JSONObject example){
        example.put(path, this.example);
    }

    @Override
    public JSONObject toJSON() {
        JSONObject json = new JSONObject();
        json.put("type", type);
        json.put("title", title);
        return json;
    }

    public String getPath() {
        return path;
    }
}
